home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / oop55.zip / FIGDEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1989-05-02  |  3KB  |  94 lines

  1.  
  2. { Copyright (c) 1989 by Borland Interational, Inc. }
  3.  
  4. program FigureDemo;
  5. { From P-47 of the Object-Oriented Programming Guide.
  6.   Extending FIGURES.PAS with type Arc.
  7. }
  8.  
  9. uses Crt, DOS, Graph, Figures;
  10.  
  11. type
  12.   Arc = object (Circle)
  13.     StartAngle, EndAngle : Integer;
  14.     constructor Init(InitX, InitY : Integer;
  15.                      InitRadius : Integer;
  16.                      InitStartAngle, InitEndAngle : Integer);
  17.     procedure Show; virtual;
  18.     procedure Hide; virtual;
  19.   end;
  20.  
  21. var
  22.   GraphDriver : Integer;
  23.   GraphMode : Integer;
  24.   ErrorCode : Integer;
  25.   AnArc : Arc;
  26.   ACircle : Circle;
  27.  
  28.  
  29. {--------------------------------------------------------}
  30. { Arc's method declarations:                             }
  31. {--------------------------------------------------------}
  32.  
  33. constructor Arc.Init(InitX,InitY : Integer;
  34.                      InitRadius : Integer;
  35.                      InitStartAngle, InitEndAngle : Integer);
  36. begin
  37.   Circle.Init(InitX, InitY, InitRadius);
  38.   StartAngle := InitStartAngle;
  39.   EndAngle   := InitEndAngle;
  40. end;
  41.  
  42. procedure Arc.Show;
  43. begin
  44.   Visible := True;
  45.   Graph.Arc(X, Y, StartAngle, EndAngle, Radius);
  46. end;
  47.  
  48. procedure Arc.Hide;
  49. var
  50.   TempColor : Word;
  51. begin
  52.   TempColor := Graph.GetColor;
  53.   Graph.SetColor(GetBkColor);
  54.   Visible := False;
  55.   { Draw the arc in the background color to hide it }
  56.   Graph.Arc(X, Y, StartAngle, EndAngle, Radius);
  57.   SetColor(TempColor);
  58. end;
  59.  
  60.  
  61. {--------------------------------------------------------}
  62. { Main program:                                          }
  63. {--------------------------------------------------------}
  64.  
  65. begin
  66.   GraphDriver := Detect; { Let the BGI determine what board
  67.                            you're using }
  68.   DetectGraph(GraphDriver, GraphMode);
  69.   InitGraph(GraphDriver, GraphMode,'');
  70.   if GraphResult <> GrOK then
  71.     begin
  72.       WriteLn('>>Halted on graphics error:',
  73.               GraphErrorMsg(GraphDriver));
  74.       Halt(1)
  75.     end;
  76.  
  77. { All descendents of type Point contain virtual methods and    }
  78. { *must* be initialized before use through a constructor call. }
  79.  
  80.   ACircle.Init(151, 82,      { Initial X,Y at 151,82 }
  81.                50);          { Initial radius of 50 pixels }
  82.   AnArc.Init(151, 82,        { Initial X,Y at 151,82 }
  83.              25, 0, 90);     { Initial radius of 50 pixels }
  84.                              { Start angle: 0; End angle: 90 }
  85.  
  86. { Replace AnArc with ACircle to drag a circle instead of an }
  87. { arc. Press Enter to stop dragging and end the program.   }
  88.  
  89.   ACircle.Drag(5);       { Parameter is # of pixels to drag by }
  90.   CloseGraph;
  91.   RestoreCRTMode;
  92. end.
  93.  
  94.